﻿#region
using System.Collections.Generic;
using YoutubeExtractor;

#endregion

namespace Y2M.Components
{
    public class ClipInfo
    {
        public ClipInfo(VideoInfo videoInfo, Clip clip)
        {
            VideoInfo = videoInfo;
            Clip = clip;
        }

        public VideoInfo VideoInfo { get; private set; }

        public Clip Clip { get; private set; }

        public string ThumbnailUrl
        {
            get { return Clip.ThumbnailUrl; }
        }

        public string DownloadUrl
        {
            get { return VideoInfo.DownloadUrl; }
        }

        public int FormatCode
        {
            get { return VideoInfo.FormatCode; }
        }

        public bool Is3D
        {
            get { return VideoInfo.Is3D; }
        }

        public int Resolution
        {
            get { return VideoInfo.Resolution; }
        }

        public string Title
        {
            get { return VideoInfo.Title; }
        }

        public string VideoExtension
        {
            get { return VideoInfo.VideoExtension; }
        }

        public VideoType VideoType
        {
            get { return VideoInfo.VideoType; }
        }

        public string Text
        {
            get { return string.Format("{0}p, {1}", Resolution, VideoType); }
        }

        public int Progress { get; set; }

        public override string ToString()
        {
            return Text;
        }
    }

    public class ClipInfoComparer : IComparer<ClipInfo>
    {
        public int Compare(ClipInfo x, ClipInfo y)
        {
            if (x.Resolution != y.Resolution)
                return x.Resolution.CompareTo(y.Resolution) * -1;

            if (x.VideoType == y.VideoType)
                return 0;

            if (x.VideoType == VideoType.Mp4)
                return -1;
            else if (y.VideoType == VideoType.Mp4)
                return 1;
            else
                return 0;
        }
    }
}